const path = require('path');
const { VueLoaderPlugin } = require('vue-loader')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin') //开启多线程进行加快速度
//商户门户打包
module.exports = {
  mode: "production",
  entry: {
    index: './src/view/index.js',
  },
  output: {
    publicPath: "./",
    filename: '[name].[chunkHash:5]' + new Date().getTime() + '.js',
  },
  resolve: {
    extensions: ['.js', '.vue'],
    alias: {
      '@': path.resolve(__dirname, './src'),
      'vue': 'vue/dist/vue.common',
      'vendor': path.resolve(__dirname, '../src/vendor'),
    }
  },
  plugins: [
    new CleanWebpackPlugin(['dist']),
    new VueLoaderPlugin,
    new HtmlWebpackPlugin({
      template: './index.html',
      filename: './index.html',
      inject: true,
      chunks: ['index'],
    }),
    new UglifyJSPlugin({
      cache: true,
      parallel: true,
      sourceMap: true
    }), //开启多线程进行打包
  ],
  module: {
    rules: [
      { test: /\.vue$/, loader: 'vue-loader' },
      { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ },
      { test: /\.css$/, loader: 'style-loader!css-loader' },
      { test: /\.json$/, loader: 'json-loader' },
      { test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)(\?\S*)?$/, loader: 'file-loader?name=[name]-[hash].[ext]&publicPath=' },
    ]
  }
};